import request from "../request";
import qs from "qs"
// 登录
export const loginApi = (params: ILoginParams): RSP<ILoginData> =>
  request.post("/admin/login", params);

export const userInfoApi = (): RSP<IUserInfo> => request.get("/admin/info");

export const getUserListApi = (
  params?: IUserListParams
): RSP<IUserListData<IUserModel>> => request.get("/admin/list", { params });

export const getMiaoshaApi = (
  params?: IUserListParams
): RSP<IUserListData<IUserModel>> => request.get("/flash/list", { params });

export const getflashSessionApi = (): RSP<ItableDataUserParams[]> => request.get("/flashSession/list");


export const userUpdateStatusApi = (
  params: IUserUpdateStatusParams
): RSP<any> =>
  request.post(`/admin/updateStatus/${params.id}?status=${params.status}`);

export const userMiaoshaApi = (
  params: IUserUpdateStatusParams
): RSP<any> =>
  request.post(`/flash/update/status/${params.id}?status=${params.status}`);

  //秒杀时间段状态修改
export const userflashSessionApi = (
  params: IUserUpdateStatusParams
): RSP<any> =>
  request.post(`/flashSession/update/status/${params.id}?status=${params.status}`);

// 用户注册
export const registerUserApi = (params: IRegisterUserParams): RSP<IUserModel> =>
  request.post("/admin/register", params);

export const createaddApi = (params: IcreateaddUserParams): RSP<IUserModel> =>
  request.post("/flash/create", params);
//添加秒杀活动
export const createflashSessionApi = (params: IflashSessionUserParams): RSP<IUserModel> =>
  request.post("/flashSession/create", params);
// 编辑
export const getUserInfoApi = (id: number): RSP<IUserModel> =>
  request.get(`/admin/${id}`);

export const updateUserInforApi = (params: IUserModel): RSP<any> =>
  request.post(`/admin/update/${params.id}`, params);
  
export const updatexiugaiApi = (params: IcreateaddUserParams): RSP<any> =>
  request.post(`/admin/update/${params.id}`, params);

export const flashupdateApi = (params: IcreateaddUserParams): RSP<any> =>
  request.post(`/flash/update/${params.id}`, params);

  //秒杀时间段编辑
  export const flashSessiondateApi = (params: IflashSessionUserParams): RSP<any> =>
  request.post(`/flashSession/update/${params.id}`, params);

export const flashdeleteApi = (id: number): RSP<any> =>
  request.post(`/flash/delete/${id}`, id); 

  //秒杀时间段删除
export const flashSessionApi = (id: number): RSP<any> =>
  request.post(`/flashSession/delete/${id}`, id); 

// 获取所有角色的列表
export const getRoleListApi = (): RSP<IRoleModel[]> =>
  request.get("/role/listAll");
// 获取指定用户的所有的角色
export const getRoleListByAdminIdApi = (adminId: number): RSP<IRoleModel[]> =>
  request.get(`/admin/role/${adminId}`);

export const updateRolesApi = ({ adminId, roleIds }: IUpdateRolesParams) =>
  request.post(
    `/admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(",")}`
  );
// 分页获取  角色列表
export const queryRoleListApi = (
  params: IUserListParams
): RSP<IUserListData<IRoleModel>> => request.get("/role/list", { params });

// 获取所有资源的接口
export const getAllResourceApi = (): RSP<IResourceModel[]> =>
  request.get("/resource/listAll");
// 获取所有的资源分类
export const getAllResourceCategoryApi = (): RSP<IResourceCategoryModel[]> =>
  request.get("/resourceCategory/listAll");
// 获取角色相关资源
export const getListRoleResourceApi = (roleId: number): RSP<IResourceModel[]> =>
  request.get(`/role/listResource/${roleId}`);



// 给角色分配资源

export const allocResourceApi = (params: IAllocResourceParams): RSP<any> =>
  request.post(
    "/role/allocResource?" + qs.stringify(params, { arrayFormat: "comma" })
  );


export const resourceLIstAPI = (params: IBackgroundRes): RSP<IUserListData<IResourceModel>> => request.get('/resource/list?' + qs.stringify(params, { arrayFormat: "comma" }))

// 添加资源数据
export const resCreateAPI = (params: IResourceModel): RSP<IUserListData<IResourceModel>> => request.post('/resource/create', params)

// 编辑资源数据
export const resCreateUpdateAPI = (params: IResourceModel): RSP<IResourceModel> => request.post(`/resource/update/${params.id}`, params)

// 点击获取ID详细数据
export const detailsAPI = (id: number): RSP<IResourceModel> => request.get(`/resource/${id}`)

export const backstageDeleteAPI = (id: number): RSP<any> => request.post(`/resource/delete/${id}`)

// 分页查询后台菜单
export const menuListAPI = (params: IBackgroundList): RSP<IUserListData<IBackgroundReturn>> => request.get(`/menu/list/${params.parentId}?pageNum=${params.pageNum}&pageSize=${params.pageSize}`)

// 分页查看下级后台菜单

// 添加后台菜单列表
export const menuCreateAPI = (params: IBackgroundReturn): RSP<IUserListData<IBackgroundReturn>> => request.post("menu/create", params)

// 通过ID删除后台菜单
export const deleteMenuAPI = (id: number) => request.post(`/menu/delete/${id}`)
// 通过ID获取当前菜单信息
export const obtainUserAPI = (id: number): RSP<IBackgroundReturn> => request.get(`/menu/${id}`)
// 编辑后台菜单数据
// export const UpdateMenuAPI = ({id,params}:IBackgroundReturn)=>request.post(`/menu/update/${id}`)
export const UpdateMenuAPI = (id: number, params: IBackgroundReturn): RSP<IUserListData<IBackgroundReturn>> => request.post(`/menu/update/${id}`, params)
// 修改菜单显示开关
export const UpdateHiddenAPI = (id: number, hidden: number): RSP<any> => request.post(`/menu/updateHidden/${id}?hidden=${hidden}`)


// 获取指定订单设置
export const getOrderSettingApi = (id: number): RSP<IOrderSetting> =>
  request.get(`/orderSetting/${id}`);
// 修该订单设置数据请求
export const orderSettingUpdateApi = (id: number, params: IOrderSetting): RSP<IOrderSetting> =>
  request.post(`/orderSetting/update/${id}`, params);

// 订单申请处理页面 分页查询退货申请(页面数据)
export const returnApplyApi = (params: IApply) =>
  request.get(`/returnApply/list`, { params });


// 退货原因设置 分页查询全部退货原因(页面数据) 
export const returnReasonApi = (params: IPage): RSP<IUserListData<TReason>> =>
  request.get("returnReason/list", { params })
// 修改退货原因启用状态  
export const returnReasonUpdateApi = (ids: number, status: number): RSP<IOrderSetting> =>
  request.post(`returnReason/update/status?status=${status}&ids=${ids}`,);
// 删除功能请求 
export const returnReasonDeleteApi = (ids: number) =>
  request.post(`returnReason/delete?ids=${ids}`);
// 添加退货原因
export const returnReasonCreateApi = (params: ICreate): RSP<any> =>
  request.post(`returnReason/create`, params);
// 获取单个退货原因 
export const getReturnReasonApi = (id: number): RSP<ICreate> =>
  request.get(`returnReason/${id}`);
// 修改退货原因
export const updateReturnReasonApi = (params: ICreate): RSP<any> =>
  request.post(`returnReason/update/${params.id}`, params);

// 订单列表页面数据 order/list
export const orderListApi = (params: IOrderList): RSP<IUserListData<any>> =>
  request.get(`order/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`, { params })

// 获取退货详情
export const getApplyApi = (id: number): RSP<any> =>
  request.get(`returnApply/${id}`)

// 获取所有收货地址
export const getcompanyAddressApi = (): RSP<IResponseParams<ICompanyAddress[]>> =>
  request.get(`companyAddress/list`)

// 添加角色
export const createRoleAPI = (params: IRoleModel): RSP<IResponseParams<IRoleModel>> => request.post("/role/create", params)
// 通过id获取当前ID的菜单数据
export const listMenuAPI = (id: number | string): RSP<IResponseParams<IBackgroundReturn>> => request.get(`role/listMenu/${id}`)

export const getTreeListAPI = () => request.get("/menu/treeList")

// 修改编辑角色信息 
export const updateRoleAPI = (id: number, role: IRoleModel): RSP<IRoleModel> => request.post(`/role/update/${id}`, role)